home *** CD-ROM | disk | FTP | other *** search
Text File | 1994-10-04 | 3.0 KB | 117 lines | [TEXT/MMCC] |
- /*================================================================================
- NextEvent.c
-
- ©1991 Greg Anderson
- greggor@apple.com
-
- This code used to abstract GetNextEvent vs. WaitNextEvent, but now
- it always calls WaitNextEvent, and therefore is largely obsolete.
-
- IMPORTANT: NextEvent returns the result of IsDialogEvent, _not_
- eventAvailable. Your code should not call IsDialogEvent,
- because NextEvent mauls the event record in ways that
- make IsDialogEvent _very_ unhappy.
- ================================================================================*/
- #include <stdio.h>
- #include <string.h>
- #include <Types.h>
- #include <OSUtils.h>
- #include <Events.h>
- #include <Resources.h>
- #include <Dialogs.h>
- #include <Controls.h>
- #include <Traps.h>
- #include <Processes.h>
-
- #include "NextEvent.h"
- #include "MacUtilities.h"
-
- /*----------------------------------------------------------------------
- // InForeground
- //
- // Return 'true' if this application is in the foreground
- ----------------------------------------------------------------------*/
- Boolean InForeground()
- {
- ProcessSerialNumber frontPSN;
- ProcessSerialNumber currentPSN;
- Boolean isSame;
-
- GetFrontProcess(&frontPSN);
- GetCurrentProcess(¤tPSN);
- SameProcess(&frontPSN, ¤tPSN, &isSame);
-
- return isSame;
- }
-
- /*----------------------------------------------------------------------
- // NextEvent
- //
- // Call GetNextEvent or WaitNextEvent.
- //
- // Does _not_ return eventAvailable (like GetNextEvent and
- // WaitNextEvent); instead, returns isDialogEvent.
- ----------------------------------------------------------------------*/
- Boolean NextEvent( short eventMask, EventRecord* event, long sleep, RgnHandle mouseRgn)
- {
- Boolean eventAvailable;
- Boolean isDialogEvent;
- GrafPtr savePort;
- Point mouseLoc;
- long ticky;
-
- /*
- // Call WaitNextEvent()
- */
- eventAvailable = WaitNextEvent( eventMask, event, sleep, mouseRgn );
-
- /*
- // We must call 'IsDialogEvent' _before_ we maul the
- // event record. Also, IsDialogEvent will not always
- // perform correctly if there is no frontmost window,
- // so we check for that case explicitly (this is an
- // undocumented problem with the Macintosh Toolbox).
- */
- isDialogEvent = false;
- if( FrontWindow() != nil )
- {
- isDialogEvent = IsDialogEvent( event );
- }
- /*
- // If the current event is NOT a dialog event, then
- // maul the event record to make it easier to parse
- // in the main event switch
- */
- if( !isDialogEvent )
- {
- /*
- // Decode suspend, resume and mouse-moved events
- */
- if( event->what == app4Evt )
- {
- if( IsSuspend(event) )
- {
- event->what = suspendEvt;
- }
- if( IsResume(event) )
- {
- event->what = resumeEvt;
- }
- if( IsMouseMoved(event) )
- event->what = mouseMovedEvt;
- }
- /*
- // If the event is an activate or deactivate event, check
- // the event modifiers and change event->what to deactivateEvt
- // if appropriate
- */
- if( event->what == activateEvt )
- {
- if( (event->modifiers & activeFlag) == 0 )
- event->what = deactivateEvt;
- }
- }
-
- return isDialogEvent;
- }
-